package com.harry.hr.dao.system.impl;

import java.util.List;

import org.hibernate.criterion.DetachedCriteria;
import org.hibernate.criterion.MatchMode;
import org.hibernate.criterion.Order;
import org.hibernate.criterion.Restrictions;
import org.springframework.orm.hibernate3.support.HibernateDaoSupport;

import com.harry.hr.dao.system.IconDAO;
import com.harry.hr.entity.system.Icon;

public class IconDAOImpl extends HibernateDaoSupport implements IconDAO {

	@SuppressWarnings("unchecked")
	public List<Icon> Query(Icon icon, MatchMode mode, Order order) {
		DetachedCriteria criteria = DetachedCriteria.forClass(Icon.class);
		if(icon!=null){
			if(icon.getName()!=null&&icon.getName().length()!=0)
				criteria.add(Restrictions.like("name", icon.getName(),mode));
			if(icon.getType()!=null&&icon.getType().length()!=0)
				criteria.add(Restrictions.like("type",icon.getType(),mode));
		}
		if(order!=null)
		criteria.addOrder(order);
		return this.getHibernateTemplate().findByCriteria(criteria);
	}

	public void delete(Icon icon) {
		this.getHibernateTemplate().delete(icon);

	}

	public Icon findByid(int id) {
		return (Icon)this.getHibernateTemplate().get(Icon.class, id);
	}

	public void save(Icon icon) {
		this.getHibernateTemplate().save(icon);

	}

	public void update(Icon icon) {
		this.getHibernateTemplate().update(icon);

	}

}
